package com.hzhk.happyrent.key;

import android.text.TextUtils;

import com.hzhk.happyrent.network.API;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * User: hzhk(1097282555@qq.com)
 * Date: 2017/11/21
 * Time: 10:58
 * progject: HappyRent
 * Describe： ${Describe}
 */
public class Encryption {
    public static String riftKeyStone() {
        return md5(getTime()+ API.HIDDEN);
    }
    public static String getTime(){
        long time=System.currentTimeMillis()/1000;//获取系统时间的10位的时间戳
        return String.valueOf(time);
    }
    private static String md5(String string) {
        if (TextUtils.isEmpty(string)) {
            return "";
        }
        MessageDigest md5 = null;
        try {
            md5 = MessageDigest.getInstance("MD5");
            byte[] bytes = md5.digest(string.getBytes());
            String result = "";
            for (byte b : bytes) {
                String temp = Integer.toHexString(b & 0xff);
                if (temp.length() == 1) {
                    temp = "0" + temp;
                }
                result += temp;
            }
            return result;
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return "";
    }
}
